<template>
  <el-card class="common-container">
    <div>功能管理</div>
    <div class="search-container">
      <!-- <el-input class="search-wrap" />
      <el-button type="primary" size="middle" icon="search" class="serchBtn">搜索</el-button> -->
      <el-button type="primary" size="middle" icon="add" class="addBtn" @click="handleAdd">添加功能</el-button>
    </div>

    <el-table :data="list" border>
      <el-table-column prop="icon" width="80px" align="center" label="图标">
        <template slot-scope="scope">
          <img class="feature-icon" :src="resBaseUrl + scope.row.icon">
        </template>
      </el-table-column>
      <el-table-column prop="name" align="center" label="功能名称" />
      <el-table-column prop="code" align="center" label="功能编码" />
      <el-table-column prop="description" align="center" label="描述" />
      <el-table-column prop="autoOpen" align="center" label="默认开通">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.autoOpen" type="success">是</el-tag>
          <el-tag v-else>否</el-tag>
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作" width="200px">
        <template slot-scope="scope">
          <el-button size="small" type="primary" class="editBtn" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      style="margin-top: 10px "
      :current-page.sync="pageNum"
      :page-size.sync="pageSize"
      layout="total, prev, pager, next"
      :total="total"
      @current-change="handleCurrentChange"
    />
    <feature-form-dialog ref="featureFormDialog" :scope="scope" />
  </el-card>
</template>

<script>
import { deleteFeature, queryFeatureList } from '@/api/feature'
import FeatureFormDialog from './FeatureFormDialog'
import { mapGetters } from 'vuex'

export default {
  name: 'Feature',
  components: {
    FeatureFormDialog
  },
  props: {
    scope: {
      require: true,
      type: Number
    }
  },
  computed: {
    ...mapGetters(['resBaseUrl'])
  },
  data() {
    return {
      pageNum: 0,
      pageSize: 10,
      loading: false,
      list: [],
      total: 0,
	  RfmDialog: false
    }
  },
  mounted() {
    this.fetchList()
  },
  methods: {
    fetchList() {
      const data = {
        pageSize: this.pageSize,
        pageNum: this.pageNum
      }
      return queryFeatureList(this.scope, data).then(res => {
        if (res.code === 0) {
          this.list = res.data.list
          this.total = res.data.total
        }
        return res
      })
    },
    handleAdd() {
      this.$refs.featureFormDialog.add().then(() => {
        this.fetchList()
      })
    },
    handleEdit(feature) {
      this.$refs.featureFormDialog.edit(feature.id).then(() => {
        this.fetchList()
      })
    },
    handleCurrentChange() {
      this.fetchList()
    },

    handleDelete(feature) {
      this.$confirm(`此操作将删除功能【${feature.name}】, 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteFeature(this.scope, feature.id).then((res) => {
          if (res.code === 0) {
            this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
            this.fetchList()
          }
        })
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .search-container {
    margin-top: 20px;
    margin-bottom: 20px;
	.addBtn, .serchBtn, .editBtn{
		background-color: $btnBgc;
		border: none;
	}
	.addBtn:hover{
		opacity: 0.5;
	}
	.serchBtn:hover{
		opacity: 0.5;
	}
	::v-deep .el-input__inner:focus{
		border-color: $btnBgc;
	}
  }
  .editBtn{
  	background-color: $btnBgc !important;
  	border: none;
	color: $btnFon;
  }
  .editBtn:hover{
  	opacity: 0.5;
  }

  .search-wrap {
    width: 500px;
    margin-right: 30px
  }
  .feature-icon{
    width: 50px;
    height: 50px;
  }

  .el-pagination.is-background .el-pager li:not(.disabled).active{
	  background-color: $btnBgc !important;
	  border: none;
	  color: $btnFon;
  }

  ::v-deep .el-input--medium .el-input__inner:focus{
	  border-color: $btnBgc;
  }
  ::v-deep .el-textarea__inner:focus{
	  border-color: $btnBgc;
  }
  ::v-deep .el-checkbox__input.is-checked .el-checkbox__inner{
	  border-color: $btnBgc;
	  background-color: $btnBgc
  }
  ::v-deep .el-checkbox__input.is-checked + .el-checkbox__label{
	  color: $btnBgc;
  }
</style>
